﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace SICOIA
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session != null)
            {
                // Code that runs when an unhandled error occurs
                //Report Error
                Exception ex = Server.GetLastError();
                HttpContext.Current.Session.Add("msgError", ex.InnerException.Message);
                //ErrorHandler.ReportError(ex); //Notifies technical team about the error
                Server.ClearError();
                /*

                // Send notification e-mail
                MailMessage Email =
                    new MailMessage("admin@yoursite.com",
                    "admin@yoursite.com");
                Email.IsBodyHtml = false;
                Email.Subject = "WEB SITE ERROR";
                Email.Body = ErrorDetails;
                Email.Priority = MailPriority.High;
                SmtpClient sc = new SmtpClient("localhost");
                sc.Credentials =
                    new NetworkCredential("EMailAccount", "Password");
                sc.Send(Email);*/

                Response.Redirect(string.Format("/Marcos/ProxyUserControls.aspx?Url=ErrorGeneral&aspxerrorpath={0}", Request.Url.PathAndQuery));
            }
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}